package com.ruoyi.web.controller.system;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.IDrTypeModeGroupService;
import com.ruoyi.system.service.IGlobalDrTypeInfoService;
import com.ruoyi.system.service.ISubService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IGlobalDrTypeModeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 全局设备类型模板Controller
 * 
 * @author yaozh
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/system/drtypemodeglobal")
public class GlobalDrTypeModeController extends BaseController
{
    @Value("${centralDatabase.dbName}")
    private String centralDatabase;
    @Resource
    private IGlobalDrTypeModeService globalDrTypeModeService;
    @Resource
    private IGlobalDrTypeInfoService globalDrTypeInfoService;
    @Resource
    private IDrTypeModeGroupService drTypeModeGroupService;
    @Resource
    private ISubService subService;

    /**
     * 查询全局设备类型模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:list')")
    @GetMapping("/list")
    public TableDataInfo list(GlobalDrTypeMode globalDrTypeMode)
    {
        startPage();
        List<GlobalDrTypeMode> list = globalDrTypeModeService.selectGlobalDrTypeModeList(globalDrTypeMode);
        return getDataTable(list);
    }

    /**
     * 导出全局设备类型模板列表
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:export')")
    @Log(title = "全局设备类型模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GlobalDrTypeMode globalDrTypeMode)
    {
        List<GlobalDrTypeMode> list = globalDrTypeModeService.selectGlobalDrTypeModeList(globalDrTypeMode);
        ExcelUtil<GlobalDrTypeMode> util = new ExcelUtil<GlobalDrTypeMode>(GlobalDrTypeMode.class);
        util.exportExcel(response, list, "全局设备类型模板数据");
    }

    /**
     * 获取全局设备类型模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:query')")
    @GetMapping(value = "/{typemodeid}")
    public AjaxResult getInfo(@PathVariable("typemodeid") Long typemodeid)
    {
        return success(globalDrTypeModeService.selectGlobalDrTypeModeByTypemodeid(typemodeid));
    }

    /**
     * 新增全局设备类型模板
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:add')")
    @Log(title = "全局设备类型模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GlobalDrTypeMode globalDrTypeMode)
    {
        return toAjax(globalDrTypeModeService.insertGlobalDrTypeMode(globalDrTypeMode));
    }

    /**
     * 修改全局设备类型模板
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:edit')")
    @Log(title = "全局设备类型模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GlobalDrTypeMode globalDrTypeMode)
    {
        return toAjax(globalDrTypeModeService.updateGlobalDrTypeMode(globalDrTypeMode));
    }

    /**
     * 删除全局设备类型模板
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:remove')")
    @Log(title = "全局设备类型模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typemodeids}")
    public AjaxResult remove(@PathVariable Long[] typemodeids)
    {
        return toAjax(globalDrTypeModeService.deleteGlobalDrTypeModeByTypemodeids(typemodeids));
    }

    /**
     * 获取设备类型树列表
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:list')")
    @GetMapping("/drTypeTree")
    public AjaxResult drTypeTree(GlobalDrTypeInfo drtypeinfo)
    {
        return success(globalDrTypeInfoService.selectDrTypeTreeList(drtypeinfo));
    }

    /**
     * 不分页，查询项目类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:list')")
    @GetMapping("/listAllGlobalDrTypeInfo")
    public AjaxResult listAllGlobalDrTypeInfo()
    {
        List<GlobalDrTypeInfo> list = globalDrTypeInfoService.selectGlobalDrTypeForAll();
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:list')")
    @GetMapping("/globalSubAllList")
    public AjaxResult globalSubAllList()
    {
        return success(subService.selectSubList(new Sub(),centralDatabase));
    }

    @PreAuthorize("@ss.hasPermi('system:drtypemodeglobal:list')")
    @GetMapping("/listAllGlobalGroup")
    public AjaxResult listAllGlobalGroup()
    {
        List<DrTypeModeGroup> list = drTypeModeGroupService.selectRegGroupForAll();
        return success(list);
    }
}
